package com.cwvs.cat.adapter;

import java.util.List;
import java.util.Random;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class ViewPagerAdapterOfMain extends PagerAdapter {
	private Random rand = new Random();
	private LayoutInflater mInflater = null;
	private Context mContext;
	private List<ImageView> mList;
//	private List<MallADPic> nList;

	public ViewPagerAdapterOfMain(Context context, List<ImageView> list/*,List<MallADPic> list1*/){
		this.mInflater = LayoutInflater.from(context);
		mList = list;
//		nList = list1;
		mContext = context;
	}
	public int getCount() {
		return Integer.MAX_VALUE;
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}
	@Override  
	public void destroyItem(View container, int position, Object object) {  
		((ViewGroup)container).removeView(mList.get(position %mList.size()));  
	}

	@Override
	public Object instantiateItem(View container, int position) {
		// TODO Auto-generated method stub
		View view = mList.get(position % mList.size());
		view.setOnClickListener(new ItemOnClickListener(position % mList.size()));
		((ViewGroup) container).addView(mList.get(position % mList.size()));
		return mList.get(position% mList.size());
	}

	public class ItemOnClickListener implements View.OnClickListener{

		private int position;

		public ItemOnClickListener(int position) {
			this.position = position;
		}

		@Override
		public void onClick(View v) {
//			Intent intent2 = new Intent(mContext,FashionWebViewAc.class);
//			intent2.putExtra("TargetURL",nList.get(position).TargetURL);
//			intent2.putExtra("Pic_Des",nList.get(position).Pic_Des);
//			mContext.startActivity(intent2);
		}

	}

}
